<!doctype html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>面登录页面</title>
</head>
<body>
<script src="https://g.alicdn.com/dingding/dingtalk-jsapi/2.13.42/dingtalk.open.js"></script>
<script>
    function getQueryVariable(variable) {
        let query = window.location.search.substring(1);
        let vars = query.split("&");
        for (let i = 0; i < vars.length; i++) {
            let pair = vars[i].split("=");
            if (pair[0] == variable) {
                return pair[1];
            }
        }
        return (false);
    }

    function exemptLogin() {
        // let corpId = getQueryVariable("corpId");
        let corpId = "ding7ae5cd0a3dfd96a4bc961a6cb783455b";
        // dd.ready参数为回调函数，在环境准备就绪时触发，jsapi的调用需要保证在该回调函数触发后调用，否则无效。
        dd.runtime.permission.requestAuthCode({
            corpId: corpId,
            onSuccess: function (result) {
                location.href = "/dingtalk/exempt?authCode=" + result.code;
            },
            onFail: function (err) {
                console.log(err);
            }

        });
    }
    // 加载成功调用免登方法
    dd.ready(function() {
        exemptLogin();
    });
</script>
</body>
</html>